package cn.com.cetccst.compliancecheck.checker;

import android.content.Context;
import android.os.Build;

import java.util.ArrayList;
import java.util.List;

import cn.com.cetccst.compliancecheck.R;
import cn.com.cetccst.tools.log.CommonLogger;

public class DeviceModelChecker extends Checker {
    private final List<String> models;

    private static DeviceModelChecker instance;
    private DeviceModelChecker(Context context) {
        super(CheckerType.DeviceModel);
        models = new ArrayList<>();
        name = context.getString(R.string.compliance_device_model);
    }

    public static void init(Context context) {
        if(instance == null) {
            instance = new DeviceModelChecker(context);
        }
    }

    public static DeviceModelChecker getInstance() {
        return instance;
    }

    @Override
    public void check(Context context) {
        String curModel = Build.MODEL;
        CommonLogger.info("Start check device model:[%s:%s]", Build.BRAND, Build.MODEL);
        super.check(context);
        if(!isEnable())
            return;
        List<String> models = getModels();
        if (models.isEmpty()) {
            setResult(CheckResult.Pass);
        }
        for (String model : models) {
            if (model.equalsIgnoreCase(curModel)) {
                setResult(CheckResult.Pass);
                return;
            }
        }
        setResult(CheckResult.Violated);
    }

    public List<String> getModels() {
        return models;
    }

    public void setModels(List<String> models) {
        this.models.clear();
        this.models.addAll(models);
    }
}
